package com.css.zfzx.fwsjcj.modules.analysis.service.impl;

import com.css.zfzx.fwsjcj.modules.analysis.service.AnalysisService;
import com.css.zfzx.fwsjcj.modules.analysis.vo.AnalysisQueryVo;
import com.css.zfzx.fwsjcj.modules.structure.service.FwBuildingStructureService;
import com.css.zfzx.fwsjcj.modules.structure.service.FwStoneStructureService;
import com.css.zfzx.fwsjcj.modules.structure.service.FwWideStructureService;
import com.css.zfzx.fwsjcj.modules.structure.service.FwWoodStructureService;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.service.CityTaskFormService;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.service.NoCityTaskFromService;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.service.VillageHouseFormService;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.service.VillagePubHouseFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author leon
 * @Title: AnalysisServiceImpl
 * @Description: 普查统计分析
 * @date 2020/6/9 11:06
 */
@Service
public class AnalysisServiceImpl implements AnalysisService {
    @Autowired
    private CityTaskFormService cityTaskFormService;
    @Autowired
    private NoCityTaskFromService noCityTaskFromService;
    @Autowired
    private VillageHouseFormService villageHouseFormService;
    @Autowired
    private VillagePubHouseFormService villagePubHouseFormService;


    @Override
    public Map<String, Object> buildingNumData(AnalysisQueryVo analysisQueryVo) {
        // 城镇住宅、城镇非住宅、农村住房、农村公共建筑 数量
        long cityTaskCount = cityTaskFormService.count(analysisQueryVo);
        long noCityTaskCount = noCityTaskFromService.count(analysisQueryVo);
        long villageHouseCount = villageHouseFormService.count(analysisQueryVo);
        long villagePubHouseCount = villagePubHouseFormService.count(analysisQueryVo);
        // X轴数据
        ArrayList<String> x = new ArrayList<>();
        x.add("城镇住宅");
        x.add("城镇非住宅");
        x.add("农村住房");
        x.add("农村公共建筑数量");
        // Y轴数据
        ArrayList<Long> y = new ArrayList<>();
        y.add(cityTaskCount);
        y.add(noCityTaskCount);
        y.add(villageHouseCount);
        y.add(villagePubHouseCount);
        // 返回结果Map
        HashMap<String, Object> map = new HashMap<>();
        map.put("x", x);
        map.put("y", y);
        return map;
    }

    @Override
    public Map<String, Object> buildingAreaData(AnalysisQueryVo analysisQueryVo) {
        // 城镇住宅、城镇非住宅、农村住房、农村公共建筑 面积
        int cityTaskCount = cityTaskFormService.areaCount(analysisQueryVo);
        int noCityTaskCount = noCityTaskFromService.areaCount(analysisQueryVo);
        int villageHouseCount = villageHouseFormService.areaCount(analysisQueryVo);
        int villagePubHouseCount = villagePubHouseFormService.areaCount(analysisQueryVo);
        // X轴数据
        ArrayList<String> x = new ArrayList<>();
        x.add("城镇住宅");
        x.add("城镇非住宅");
        x.add("农村住房");
        x.add("农村公共建筑数量");
        // Y轴数据
        ArrayList<Integer> y = new ArrayList<>();
        y.add(cityTaskCount);
        y.add(noCityTaskCount);
        y.add(villageHouseCount);
        y.add(villagePubHouseCount);
        // 返回结果Map
        HashMap<String, Object> map = new HashMap<>();
        map.put("x", x);
        map.put("y", y);
        return map;
    }

    @Override
    public List<Map> buildingCityNumDataByStructureType(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"砖混", "底层混凝土柱-上部砖混", "钢筋混凝土", "砖木", "钢结构", "木结构", "其它"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String structureType : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setStructureType(structureType);
            Long count = 0L;
            // 柱类型数量
            long cityTaskCount = cityTaskFormService.count(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.count(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", structureType);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingVillageNumDataByStructureType(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"砖(砌块)混","混凝土结构(框架、剪力墙)","轻钢（钢）装配式","混凝土装配式","砖木","土木","石木","木结构","窑洞","混杂结构（砖/砌块/土/石）","其它"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String structureType : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setStructureType(structureType);
            Long count = 0L;
            // 农村住房、农村公共建筑 数量
            long villageHouseCount = villageHouseFormService.count(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.count(analysisQueryVo);
            count = villageHouseCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", structureType);
            result.add(map);

        }
        return result;
    }

    @Override
    public List<Map> buildingCityAreaDataByStructureType(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"砖混", "底层混凝土柱-上部砖混", "钢筋混凝土", "砖木", "钢结构", "木结构", "其它"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String structureTyp : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setStructureType(structureTyp);
            Long count = 0L;
            // 城镇住宅、城镇非住宅 数量
            long cityTaskCount = cityTaskFormService.areaCount(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.areaCount(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", structureTyp);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingVillageAreaDataByStructureType(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"砖(砌块)混","混凝土结构(框架、剪力墙)","轻钢（钢）装配式","混凝土装配式","砖木","土木","石木","木结构","窑洞","混杂结构（砖/砌块/土/石）","其它"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String structureTyp : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setStructureType(structureTyp);
            Long count = 0L;
            // 农村住房、农村公共建筑 数量
            long villageHouseCount = villageHouseFormService.areaCount(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.areaCount(analysisQueryVo);
            count = villageHouseCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", structureTyp);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingNumDataByBuildingTime(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"70s以前", "70s", "80s", "90s", "00s", "10s"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String buildingTime : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setBuildingTime(buildingTime);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村住房、农村公共建筑 数量
            long cityTaskCount = cityTaskFormService.count(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.count(analysisQueryVo);
            long villageHouseCount = villageHouseFormService.count(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.count(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villageHouseCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", buildingTime);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingAreaDataByBuildingTime(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"70s以前", "70s", "80s", "90s", "00s", "10s"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String buildingTime : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setBuildingTime(buildingTime);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村住房、农村公共建筑 面积
            long cityTaskCount = cityTaskFormService.areaCount(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.areaCount(analysisQueryVo);
            long villageHouseCount = villageHouseFormService.areaCount(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.areaCount(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villageHouseCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", buildingTime);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingNumDataByFortificationIntensity(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"未设防", "6度", "7度", "8度", "9度", "10度"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String nowFortificationIntensity : array) {
            // 设防类型查询参数变化
            analysisQueryVo.setNowFortificationIntensity(nowFortificationIntensity);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村住房、农村公共建筑 数量
            long cityTaskCount = cityTaskFormService.count(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.count(analysisQueryVo);
            //long villageHouseCount = villageHouseFormService.count(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.count(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", nowFortificationIntensity);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingAreaDataByFortificationIntensity(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"未设防", "6度", "7度", "8度", "9度", "10度"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String nowFortificationIntensity : array) {
            // 结构类型查询参数变化
            analysisQueryVo.setNowFortificationIntensity(nowFortificationIntensity);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村住房、农村公共建筑 面积
            long cityTaskCount = cityTaskFormService.areaCount(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.areaCount(analysisQueryVo);
            //long villageHouseCount = villageHouseFormService.areaCount(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.areaCount(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", nowFortificationIntensity);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingNumDataByResult(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"未抗震设防", "抗震设防能力不足", "基本符合抗震设防要求"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String conclusions : array) {
            // 初步结论类型 查询参数变化
            analysisQueryVo.setResult(conclusions);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村公共建筑 数量
            long cityTaskCount = cityTaskFormService.count(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.count(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.count(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", conclusions);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingAreaDataByResult(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"未抗震设防", "抗震设防能力不足", "基本符合抗震设防要求"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String conclusions : array) {
            // 初步结论类型 查询参数变化
            analysisQueryVo.setResult(conclusions);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村公共建筑 数量
            long cityTaskCount = cityTaskFormService.areaCount(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.areaCount(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.areaCount(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", conclusions);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingNumDataByHouseUseSituation(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"自用", "空置", "出租", "经营", "被征或待征", "其他"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String houseUseSituation : array) {
            // 初步结论类型 查询参数变化
            analysisQueryVo.setHouseUseSituation(houseUseSituation);
            Long count = 0L;
            // 农村住房 数量
            long villageHouseCount = villageHouseFormService.count(analysisQueryVo);
            count = villageHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", houseUseSituation);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingAreaDataByHouseUseSituation(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"自用", "空置", "出租", "经营", "被征或待征", "其他"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String houseUseSituation : array) {
            // 初步结论类型 查询参数变化
            analysisQueryVo.setHouseUseSituation(houseUseSituation);
            Long count = 0L;
            // 农村住房 数量
            long villageHouseCount = villageHouseFormService.areaCount(analysisQueryVo);
            count = villageHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", houseUseSituation);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingNumDataByHouseMeasures(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"基本完备", "部分具备", "完全没有"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String houseMeasures : array) {
            // 房屋使用情况类型 查询参数变化
            analysisQueryVo.setHouseMeasures(houseMeasures);
            Long count = 0L;
            // 农村住房数量
            long villageHouseCount = villageHouseFormService.count(analysisQueryVo);
            count = villageHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", houseMeasures);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingAreaDataByHouseMeasures(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"基本完备", "部分具备", "完全没有"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String houseMeasures : array) {
            // 房屋使用情况类型 查询参数变化
            analysisQueryVo.setHouseMeasures(houseMeasures);
            Long count = 0L;
            // 农村住房数量
            long villageHouseCount = villageHouseFormService.areaCount(analysisQueryVo);
            count = villageHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", houseMeasures);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingNumDataByBuildingIsDamage(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"有", "无"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String isDamage : array) {
            // 居住房屋有无明显可见的裂缝、变形、倾斜等类型 查询参数变化
            analysisQueryVo.setIsDamage(isDamage);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村公共建筑 数量
            long cityTaskCount = cityTaskFormService.count(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.count(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.count(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", isDamage);
            result.add(map);
        }
        return result;
    }

    @Override
    public List<Map> buildingAreaDataByBuildingIsDamage(AnalysisQueryVo analysisQueryVo) {
        String[] array = new String[]{"有", "无"};
        // 饼数据
        ArrayList<Map> result = new ArrayList<>();
        for (String isDamage : array) {
            // 居住房屋有无明显可见的裂缝、变形、倾斜等类型 查询参数变化
            analysisQueryVo.setIsDamage(isDamage);
            Long count = 0L;
            // 城镇住宅、城镇非住宅、农村公共建筑 数量
            long cityTaskCount = cityTaskFormService.areaCount(analysisQueryVo);
            long noCityTaskCount = noCityTaskFromService.areaCount(analysisQueryVo);
            long villagePubHouseCount = villagePubHouseFormService.areaCount(analysisQueryVo);
            count = cityTaskCount + noCityTaskCount + villagePubHouseCount;
            HashMap<String, Object> map = new HashMap<>();
            map.put("value", count);
            map.put("name", isDamage);
            result.add(map);
        }
        return result;
    }
}
